﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

namespace UdrinkWater_Project.Admin
{
    public partial class ReportManufac1 : System.Web.UI.Page
    {
        private string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            string Manu_ID = Session["ManuDateID"].ToString();
            string list = Session["list"].ToString();
            //string a = Session["DocDate"].ToString();
            //DateTime docDate = Convert.ToDateTime(a);

            //string DocDate = ConvestToDateN((docDate.Date).ToShortDateString());
            //string b = Session["DeeadLine"].ToString();
            //DateTime DeadLine = Convert.ToDateTime(a);
            //string DeeadLine = ConvestToDateN((DeadLine.Date).ToShortDateString());
            //string PrintDate = ConvestToDateN((DateTime.Now).ToShortDateString());


            SqlConnection objConn = new SqlConnection();
            SqlCommand objCmd = new SqlCommand();
            SqlDataAdapter dtAdapter = new SqlDataAdapter();

            DataSet ds = new DataSet();
            DataTable dt = null;
            string strConnString = null;
            StringBuilder strSQL = new StringBuilder();

            
            strSQL.Append(" SELECT        ROW_NUMBER() OVER(ORDER BY TB_Manufacture.Product_ID asc) AS Row,TB_Manufacture.Manu_Date, TB_Manufacture.Product_ID, TB_Product.Product_name, TB_Manufacture.Product_Count, TB_Unit_Category.Unit_Name, ");
            strSQL.Append(" TB_Manufacture.Act_Officer,( TB_Employee.Prefix +' '+TB_Employee.Firstname +' '+ TB_Employee.Lastname) AS EmpName ");
            strSQL.Append(" FROM            TB_Manufacture LEFT JOIN ");
            strSQL.Append(" TB_Product ON TB_Manufacture.Product_ID = TB_Product.Product_ID LEFT JOIN ");
            strSQL.Append(" TB_Unit_Category ON TB_Product.Unit = TB_Unit_Category.Unit_ID LEFT JOIN ");
            strSQL.Append(" TB_Employee ON TB_Manufacture.Act_Officer = TB_Employee.ID_Card ");
            strSQL.Append(" WHERE TB_Manufacture.Manu_Date ='" + Manu_ID + "' ");
            // strSQL.Append("order by Product_ID asc");

            objConn.ConnectionString = Connection;
            var _with1 = objCmd;
            _with1.Connection = objConn;
            _with1.CommandText = strSQL.ToString();
            _with1.CommandType = CommandType.Text;
            dtAdapter.SelectCommand = objCmd;

            dtAdapter.Fill(ds, "rptManuFac1");
            dt = ds.Tables[0];

            dtAdapter = null;
            objConn.Close();
            objConn = null;

            ReportDocument rpt = new ReportDocument();
            rpt.Load(Server.MapPath("~/Officer/rptManuFac1.rpt"));
            rpt.SetDataSource(dt);
            rpt.SetParameterValue("list", list);
            //this.CrystalReportViewer1.ReportSource = rpt;
            rpt.ExportToHttpResponse
            (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "ManuList");
           
        }
    }
}